﻿/* tslint:disable:jsdoc-format max-line-length */
// warning: Generated code! Do not change!
module App.Services {
	"use strict";
	export class AjaxHelper {
		private $http: angular.IHttpService;
		private $q: angular.IQService;
		public baseUrl: string;

		constructor(baseUrl: string) {
			this.$http = <angular.IHttpService>angular.injector(["ng"]).get("$http");
			this.$q = <angular.IQService>angular.injector(["ng"]).get("$q");
			if (baseUrl.match(/\/$/)) {
				baseUrl += "/";
			}
			this.baseUrl = baseUrl;
		}

		request<T>(url: string, httpVerb: string, data?: any): angular.IPromise<T> {
			var config: ng.IRequestConfig = {
				url: this.baseUrl + url,
				cache: false,
				method: httpVerb,
				headers: { "Content-Type": "application/json" }
			};

			if (data) {
				config.data = data;
			}

			var deferred: angular.IDeferred<T> = this.$q.defer();
			this.$http(config).then(
				(response: angular.IHttpPromiseCallbackArg<T>) => {
					deferred.resolve(response.data);
				},
				(response: angular.IHttpPromiseCallbackArg<any>) => {
					deferred.reject(response);
					console.error("HTTP error", response.status, response.data);
				}
			);
			return deferred.promise;
		}
	}
	export class ValuesProxy {
		public baseUrl: string;
		constructor(baseUrl: string = "") {
			this.baseUrl = baseUrl;
		}

		Get(): angular.IPromise<Array<string>> {
			return new AjaxHelper(this.baseUrl).request<Array<string>>("api/values/Get", "GET");
		}

		GetById(id: number): angular.IPromise<string> {
			return new AjaxHelper(this.baseUrl).request<string>("api/values/Get?id=" + id, "GET");
		}

		Post(/** [FromBody] **/value: string): angular.IPromise<void> {
			return new AjaxHelper(this.baseUrl).request<void>("api/values/Post", "POST", JSON.stringify(value));
		}

		PutById(id: number, /** [FromBody] **/value: string): angular.IPromise<void> {
			return new AjaxHelper(this.baseUrl).request<void>("api/values/Put?id=" + id, "PUT", JSON.stringify(value));
		}

		DeleteById(id: number): angular.IPromise<void> {
			return new AjaxHelper(this.baseUrl).request<void>("api/values/Delete?id=" + id, "DELETE");
		}
	}
}
